#!/bin/bash

#set -e

# Pull registry:2 image and run it
if [[ `docker ps | grep registry | wc -l` > 0 ]]; then
  docker stop registry-srv
  docker rm registry-srv
fi

echo "prepare cert for booting docker..."
mkdir -p /etc/docker-registry/certs/
cp certs/server.pem   /etc/docker-registry/certs/
cp certs/server-key.pem   /etc/docker-registry/certs/

docker run -d -v /var/lib/docker-registry:/var/lib/registry \
       -v /etc/docker-registry/certs:/certs \
       -e REGISTRY_STORAGE_DELETE_ENABLED="true" \
       -e REGISTRY_HTTP_ADDR=0.0.0.0:443 \
       -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/server.pem\
       -e REGISTRY_HTTP_TLS_KEY=/certs/server-key.pem  \
       -p 443:443 \
       --restart=always --name registry-srv  \
	    docker.m.daocloud.io/registry:2.5

#       registry:2 , 不要使用registry:2，版本是指向最新版本,版本不具体就容易出问题。


echo "install cert..."
cp certs/root/ca.pem  /etc/docker/certs.d/pastack-registry.paic.com.cn/ca.crt
